package com.example.shardingSphere.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.shardingSphere.base.AbstractService;
import com.example.shardingSphere.base.BasicMapper;
import com.example.shardingSphere.dao.UserMapper;
import com.example.shardingSphere.entity.UserInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Breet
 * @Date: 2019/7/10 11:43
 * @Description:
 */
@Service
public class UserInfoService extends AbstractService<UserMapper, UserInfo> {

    @Resource
    private UserMapper userMapper;

    public BasicMapper getBaseMapper() {
        return userMapper;
    }

    public List<UserInfo> ge() {
        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(UserInfo::getAge, "5")
                .orderByDesc(UserInfo::getId);
        return getBaseMapper().selectList(queryWrapper);
    }

    public boolean save(UserInfo entity) {
        return super.save(entity);
    }

    public List<UserInfo> getUserList() {
        return getBaseMapper().selectList(Wrappers.<UserInfo>lambdaQuery());
    }


    public List<UserInfo> between() {
        /***
         *  ***尚未清楚为什么 between and 语句不行
         */
        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.between(UserInfo::getAge, 3, 9)
                .orderByDesc(UserInfo::getId);

        return getBaseMapper().selectList(queryWrapper);
    }

    public List<UserInfo> gele() {
        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(UserInfo::getAge, 3);
        queryWrapper.le(UserInfo::getAge, 15);
        return getBaseMapper().selectList(queryWrapper);
    }

}
